/**
 * 档案借阅----借阅申请
 */
import React from "react";
import PropTypes from "prop-types";
import { routerRedux } from "dva/router";
import { connect } from "dva";
import { Row, Col, Button, Tabs } from "antd";
import Filter from "./Filter";
import Tab from "./Tab";
import Modal from "./Modal";

const TabPane = Tabs.TabPane;

class Application extends React.Component {
  constructor(props) {
    super(props);

    this.state = {};
  }

  componentDidMount(){
    const { getList,menu,pagination } = this.props
    const params = {
      operatingState:menu,
      page:pagination.current
    }
    getList(params)
  }
  render() {
    
    const {
      list,
      pagination,
      modalVisibleApp,
      currentItem,
      userList,
      menu,
      dispatch,
      loading
    } = this.props;
    const showModal = record => {
      dispatch({
        type: "borrow/showModal",
        payload: { record }
      });
    };
    const hideModal = () => {
      dispatch({
        type: "borrow/hideModal"
      });
    };
    const handleModal = value => {
      dispatch({
        type: "borrow/saveApplication",
        payload: value
      });
      hideModal();
    };
    const handleSearch = value => {
      dispatch({
        type: "borrow/query",
        payload: { ...value }
      });
    };

    const tabProps = {
      loading:loading.effects['borrow/query'],
      dataSource: list,
      // rowKey: record => record.createdUserId,
      pagination,
      onChange(page) {
        dispatch({
          type: "borrow/query",
          payload: { page: page.current, pageSize: page.pageSize }
        });
      },
      showModal: showModal
    };
    const modalProps = {
      title: "档案借阅",
      visible: modalVisibleApp,
      onCancel: hideModal,
      onOk: handleModal,
      currentItem,
      userList
    };
    const filterProps = {
      userList,
      handleSearch
    };
    return (
      <div>
        <Filter {...filterProps} />
        <Tab {...tabProps} />
        {modalVisibleApp && <Modal {...modalProps} />}
      </div>
    );
  }
}

Application.propTypes = {
  location: PropTypes.object,
  borrow: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object
};

export default connect(({ loading, borrow, newfile }) => ({
  loading,
  borrow,
  newfile
}))(Application);
